<?php

namespace common\service;

use support\SingletonTrait;
use Webman\Stomp\Client;

class AsyncCallService
{
    use SingletonTrait;

    /**
     * 生成实体任务 异步队列执行
     * @param int $projectId
     * @param $moduleCode
     * @param string $entityIds
     * @return array
     */
    public function generateEntityStepCategoryTask(int $projectId, $moduleCode, string $entityIds)
    {
        Client::send('generate_entity_step_category_task', build_queue_data_with_xu([
            'project_id' => $projectId,
            'module_code' => $moduleCode,
            'entity_id_str' => $entityIds,
        ]));
        return [
            'success' => [],
            'error' => [],
            'added' => [],
        ];
    }

    /**
     * 异步同步概念的关联关系
     * @update 2021年7月22日 可以同步分镜的关联关系到序列与镜头中
     * @param $designId
     * @param string $moduleCode
     */
    public function syncRelationDataAsync($designId, string $moduleCode)
    {
        Client::send('sync_design_relation_data', build_queue_data_with_xu([
            'id' => $designId,
            'module_code' => $moduleCode,
        ]));
    }

    /**
     * 同步关联关系
     * @param $designId
     * @param int $delay
     * @return void
     */
    public function syncRelationDataToEntityRelationShipsAsync($designId, int $delay = 0)
    {
        Client::send('sync_relation_data_to_entity_relation_ships', build_queue_data_with_xu([
            'id' => $designId,
        ]), $delay);
    }
}
